package com.zpark;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

/**
 * 配置类
 */
@Configuration
@ComponentScan("com.zpark")
@PropertySource("classpath:jdbc.properties")
public class SpringConfig {

    @Value("${driver}")
    private String driver;

    @Value("${url}")
    private String url;

    @Value("${uname}")
    private String uname;

    @Value("${pwd}")
    private String pwd;

    @Bean
    public JdbcTemplate getJdbcTemplate(DataSource source){
        return new JdbcTemplate(source);
    }

    @Bean
    public DataSource getDataSource(){
        DriverManagerDataSource source = new DriverManagerDataSource();

        source.setDriverClassName(driver);
        source.setPassword(pwd);
        source.setUsername(uname);
        source.setUrl(url);

        return source;
    }
}
